@extends('admin.index')
@section('content')
    <style>
    </style>
    <div class="layui-main">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>视频管理</legend>
        </fieldset>
        <blockquote class="layui-elem-quote">编辑视频</blockquote>
        <form class="layui-form" method="post" action="{{url('/adm/video/doeditvideo')}}"  id="form_data" enctype="multipart/form-data">
            <input type="hidden" name="_token" value="{{ csrf_token() }}" />
            <input type="hidden" name="id" value="{{$info['id']}}">
            <fieldset class="layui-elem-field">
                <legend>填写信息</legend>
                <div class="layui-field-box">
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题：</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" placeholder="视频标题" value="{{$info['title']}}" class="layui-input" >
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">内容：</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入内容" name="contents" class="layui-textarea neirong">{{$info['content']}}</textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">模块：</label>
                        <div class="layui-input-block">
                            <select name="module" id="module">
                                <option {{$info['module'] == 1 ? "selected" : ''}} value="1">开心通告栏</option>
                                <option {{$info['module'] == 2 ? "selected" : ''}} value="2">麦麦开心跳</option>
                                <option {{$info['module'] == 3 ? "selected" : ''}} value="3">麦麦一起玩</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">上传视频封面：</label>
                        <div class="layui-box layui-upload-button">
                            <input type="file" name="images" class="layui-upload-file" id="banner_two">
                            <span class="layui-upload-icon"><i class="layui-icon"></i>上传图片</span>
                        </div>
                        <span style="color: red">建议：图片文件大小在1M以内，以保证用户浏览时的不会出现加载过慢的情况</span>
                        <sapn class="old_small_img"  style="margin-left: 6%">
                            <img style="width:100px;height:100px" src="{{env('CDN_URL').$info['img_url']}}" alt="">
                        </sapn>
                        <div id="content_banner_one"></div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">上传视频：</label>
                        <div class="layui-box layui-upload-button">
                            <input type="file" name="video_url" class="layui-upload-file" id="video_input">
                            <span class="layui-upload-icon"><i class="layui-icon"></i>上传视频</span>
                        </div>
                        <span style="color: red">建议：视频文件大小在10M以内，以保证用户浏览时的不会出现加载过慢的情况</span>
                        <div id="em" style="margin-left: 10%"></div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">排序：</label>
                        <div class="layui-input-inline">
                            <input type="number" min=1 name="sort" placeholder="" value="{{$info['sort']}}" class="layui-input">
                        </div>
                    </div>
                </div>
            </fieldset>
            <div class="layui-form-item text-center" >
                {{--<div class="layui-input-block">--}}
                <button class="layui-btn">确认修改</button>
                {{--</div>--}}
            </div>
        </form>
    </div>
    <script>
        $(function () {
            $('#banner_two').change(function(){
                var inputElement = document.getElementById('banner_one');
                var fileList = this.files;
                var reader = new FileReader();
                reader.readAsDataURL(fileList[0]);
                reader.onload = function(e) {
                    var image = new Image();
                    image.src = e.target.result;
                    image.onload=function(){
                        console.log(image.width);
                        console.log(image.height);
                        var bili = image.width/image.height;
                        var www = 120/bili;
                        $('.old_small_img').html('');
                        $('#content_banner_one').html("<img style='float:left;margin:10px 0px 10px 180px;' src='"+image.src+"' width='120px' height='"+www+"px'/>");
                    }
                };
            });

            $('#video_input').change(function(){
                $('#em').text($('#video_input').val());
            });


            $('#form_data').submit(function(){
                var $title = $('input[name=title]').val();
                var $img_url = $('input[name=images]').val();
                var $sort = $('input[name=sort]').val();
                var $content = $('.neirong').val();
                var $module = $('#module').val();
                if (!$title) {
                    layer.msg('名称不能为空', {icon: 5});
                    return false;
                }
                /*if (!$content) {
                    layer.msg('内容不能为空', {icon: 5});
                    return false;
                }*/
                if (!$module) {
                    layer.msg('所属模块不能为空', {icon: 5});
                    return false;
                }
                if (!$sort) {
                    layer.msg('排序不能为空', {icon: 5});
                    return false;
                }
                layer.msg('正在上传视频，请不要刷新页面，上传成功会自动刷新...', {
                    time: 600000, //多少秒后自动关闭
                    btn: ['明白了']
                });
                /*$.ajax({
                    url : '/adm/video/doaddbanner',
                    type : 'post',
                    dateType : 'json',
                    data : $('#form_data').serialize(),
                    success : function(msg){
                        layer.msg(msg.msg, {icon: 6});
                        console.log(msg);
                        return false;
                        window.location.href = '{{url("adm/video/bannerlist")}}';
                    },
                    error : function(msg){
                        console.log(msg);
                    }
                });*/

            })
        })

    </script>
@endsection

